/**
 * 
 */
package main.org.action;

import java.math.BigDecimal;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import main.org.model.Amount;
import main.org.model.Budget;
import main.org.model.Utils;

import org.compiere.model.MBPMVersionBudget;
import org.compiere.model.MClient;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.EMail;
import org.compiere.util.Env;
import org.compiere.util.EMail;


/**
 * @author a.nurpiissov
 * 
 */
public class test extends Budget implements ServletRequestAware, ServletResponseAware {
	
	private HttpServletRequest request;
	private HttpServletResponse response;
	/**
	 * 
	 */
	private static final long serialVersionUID = -823450726985416943L;
	/** Logger */
	protected CLogger log = CLogger.getCLogger(getClass());

	/* 
	 */
	@Override
	public String execute() throws Exception {

		String action = request.getParameter("action");
		String BPM_VersionBudget_ID = request.getParameter("BPM_VersionBudget_ID");
		
		if(action == null || BPM_VersionBudget_ID == null)
			return NONE;
			
		
		if(action.equals("getStatus")){
			
			MBPMVersionBudget vb = new MBPMVersionBudget(Env.getCtx(), Integer.parseInt(BPM_VersionBudget_ID), null);
			response.setContentType("text/xml;charset=UTF-8");
			response.getWriter().write("{"+'"'+"result"+'"'+":"+'"'+vb.getStatus()+'"'+"}");
		}
		else if(action.equals("getUser")){
			int userid = Env.getAD_User_ID(Env.getCtx());
			System.out.println("_________AD_User: " + userid);
//			MBPMVersionBudget vb = new MBPMVersionBudget(Env.getCtx(), Integer.parseInt(BPM_VersionBudget_ID), null);
			response.setContentType("text/xml;charset=UTF-8");
			response.getWriter().write("{"+'"'+"result"+'"'+":"+'"'+userid+'"'+"}");
		}
		
		else{
//			System.out.println("test parameters: BPM_VersionBudget_ID = "+BPM_VersionBudget_ID+", action: " + action);
			MBPMVersionBudget vb = new MBPMVersionBudget(Env.getCtx(), Integer.parseInt(BPM_VersionBudget_ID), null);
			if(action == null)
				action = "";
			
//			if()
			
			vb.setStatus(action);
			vb.save();
			
			MClient client = new MClient(Env.getCtx(), Env.getAD_Client_ID(Env.getCtx()), null);
			
			EMail mail = new EMail(client, "g.nurpiissova@gmail.com","nurpiisov@gmail.com", "test", "text body" );
			mail.send();
			
		}
		
//		setAmt(getValues(callID, chargeID, periodID));
//		setPage(Utils.TEMPLATE_SECOND);
//
//		session.put("chargeamount", this);
//
//		if (amt.length > 0)
//			return SUCCESS;
//		else
			return null;
	}

	public HttpServletRequest getServletRequest() {
		return request;
	}

	public HttpServletResponse getServletResponse() {
		return response;
	}

	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

}
